<template>
  <el-button @click="selectFileTempList">{{ label }}<i class="el-icon-download el-icon--right"></i></el-button>
</template>

<script>
export default {

  props: {
    label: String,
    title: String,
    service: {
      type: String,
    },
    module: {
      type: String,
    },
    system: {
      type: String,
      default: 'OMS'
    },
  },
  data() {
    return {
      temps: [],
    }
  },
  methods: {
    loadFileTemp(call) {
      this.$ajax({
        url: this.system == 'WMS' ? this.$url['wms/baseTemplate'] : this.$url['oms/baseTemplate'],
        method: 'post',
        loading: true,
        data: {
          service: this.service,
          module: this.module,
        },
        success: (res) => {
          this.temps = res.data.rows
          call()
        }
      })
    },
    selectFileTempList() {
      if (_.isEmpty(this.temps)) {
        this.loadFileTemp(() => {
          this.showTempList(this.temps)
        })
        return
      }
      this.showTempList(this.temps)
    },
    showTempList(list) {
      this.$msgbox_filelist(list, {
        title: this.title || this.label,
      })
    },
  },
}
</script>

